﻿@{
    ViewBag.Title = "Add";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutForm.cshtml";
}

<div class="layui-col-md12 top10">
    <form class="layui-form" id="form" action="/Blog/Article/Add" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="Title" lay-verify="required" lay-vertype="tips" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">摘要</label>
            <div class="layui-input-block">
                <input type="text" name="ZhaiYao" lay-verify="required" lay-vertype="tips" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面</label>
            <div class="layui-input-inline">
                <input name="ImgUrl" lay-verify="required" readonly id="HeadShot" class="layui-input">
            </div>
            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                <button type="button" class="layui-btn layui-btn-primary" id="btnUpload">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea id="Content" name="Content" lay-verify="concact"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">添加时间</label>
            <div class="layui-input-block">
                <input type="text" name="CreateOn" id="CreateOn" readonly lay-verify="required" lay-vertype="tips" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
                @Html.DropDownList("ClassId", null, "-请选择分类-", new Dictionary<string, object> { { "lay-verify", "required" }, { "lay-vertype", "tips" }, { "class", "layui-input" } })
            </div>
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                @Html.DropDownList("TypeId", null, "-请选择类型-", new Dictionary<string, object> { { "lay-verify", "required" }, { "lay-vertype", "tips" }, { "class", "layui-input" } })
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否置顶</label>
            <div class="layui-input-inline">
                @Html.DingRadioHtml(false)
            </div>
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                @Html.StatusRadioHtml(true)
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="submitForm" id="submitForm">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['upload', 'form', 'layedit', 'layer', 'laydate'], function () {
        var upload = layui.upload;
        var layer = layui.layer;
        var form = layui.form;
        var layedit = layui.layedit;
        var laydate = layui.laydate;
        var $ = layui.$;
        laydate.render({
            elem: '#CreateOn',
            type: 'datetime'
        });
        var uploadInst = upload.render({
            elem: '#btnUpload' //绑定元素
            , url: '/SysSet/Info/ExportFile/' //上传接口
            , size: '@ViewBag.MaxFileUpload'
            , exts: '@ViewBag.UploadFileType'
            , done: function (res) {  //上传完毕回调
            //假设code=0代表上传成功
            if (res.code == 0) {
                //do something （比如将res返回的图片链接保存到表单的隐藏域）
                $("#HeadShot").val(res.data.src);
                }
            }
            , error: function () { //请求异常回调

            }
        });
        layer.photos({
            photos: '#layer-photos-demo',
            anim: 1
        });
        layedit.set({
            uploadImage: {
                url: '/SysSet/Info/ExportFile/' //接口url
                , type: 'post' //默认post
            }
        });
        form.verify({
            concact: function (value, item) { //value：表单的值、item：表单的DOM对象
                layedit.sync(index);
            }
        })
        var index = layedit.build('Content'); //建立编辑器
        //富文本框不知道怎么验证，所以还是用了母版页的监听
        submitForm(form, "添加成功"); //监听提交
    });
</script>

